]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
WorkspaceSwitcher: simplify code for handling keybindings
authorGiovanni Campagna <gcampagna@src.gnome.org>
Sat, 14 Apr 2012 12:40:30 +0000 (14:40 +0200)
committerGiovanni Campagna <gcampagna@src.gnome.org>
Wed, 27 Jun 2012 17:35:37 +0000 (19:35 +0200)
Most of code implementing workspace switches was repeated with
minor differences on each direction. Instead, consolidate it
and use the new meta_workspace_get_neighbor.

https://bugzilla.gnome.org/show_bug.cgi?id=674104

js/ui/windowManager.js
js/ui/workspaceSwitcherPopup.js
js/ui/workspacesView.js

index c6b17ad25497b0d28f815d77759db9e1e980435e..429253732180b95f11895b5fd0c7edff4baa1508 100644 (file)
@@ -564,72 +564,23 @@ const WindowManager = new Lang.Class({
             this._workspaceSwitcherPopup = new WorkspaceSwitcherPopup.WorkspaceSwitcherPopup();
 
         if (binding.get_name() == 'switch-to-workspace-up')
-            this.actionMoveWorkspaceUp();
+            this.actionMoveWorkspace(Meta.MotionDirection.UP);
         else if (binding.get_name() == 'switch-to-workspace-down')
-            this.actionMoveWorkspaceDown();
-        // left/right would effectively act as synonyms for up/down if we enabled them;
-        // but that could be considered confusing.
-        // else if (binding.get_name() == 'switch-to-workspace-left')
-        //   this.actionMoveWorkspaceLeft();
-        // else if (binding.get_name() == 'switch-to-workspace-right')
-        //   this.actionMoveWorkspaceRight();
-    },
-
-    actionMoveWorkspaceLeft: function() {
-        let rtl = (Clutter.get_default_text_direction() == Clutter.TextDirection.RTL);
-        let activeWorkspaceIndex = global.screen.get_active_workspace_index();
-        let indexToActivate = activeWorkspaceIndex;
-        if (rtl && activeWorkspaceIndex < global.screen.n_workspaces - 1)
-            indexToActivate++;
-        else if (!rtl && activeWorkspaceIndex > 0)
-            indexToActivate--;
-
-        if (indexToActivate != activeWorkspaceIndex)
-            global.screen.get_workspace_by_index(indexToActivate).activate(global.get_current_time());
-
-        if (!Main.overview.visible)
-            this._workspaceSwitcherPopup.display(WorkspaceSwitcherPopup.UP, indexToActivate);
+            this.actionMoveWorkspace(Meta.MotionDirection.DOWN);
+        else if (binding.get_name() == 'switch-to-workspace-left')
+            this.actionMoveWorkspace(Meta.MotionDirection.LEFT);
+        else if (binding.get_name() == 'switch-to-workspace-right')
+            this.actionMoveWorkspace(Meta.MotionDirection.RIGHT);
     },
 
-    actionMoveWorkspaceRight: function() {
-        let rtl = (Clutter.get_default_text_direction() == Clutter.TextDirection.RTL);
-        let activeWorkspaceIndex = global.screen.get_active_workspace_index();
-        let indexToActivate = activeWorkspaceIndex;
-        if (rtl && activeWorkspaceIndex > 0)
-            indexToActivate--;
-        else if (!rtl && activeWorkspaceIndex < global.screen.n_workspaces - 1)
-            indexToActivate++;
+    actionMoveWorkspace: function(direction) {
+        let activeWorkspace = global.screen.get_active_workspace();
+        let toActivate = activeWorkspace.get_neighbor(direction);
 
-        if (indexToActivate != activeWorkspaceIndex)
-            global.screen.get_workspace_by_index(indexToActivate).activate(global.get_current_time());
+        if (toActivate && activeWorkspace != toActivate)
+            toActivate.activate(global.get_current_time());
 
         if (!Main.overview.visible)
-            this._workspaceSwitcherPopup.display(WorkspaceSwitcherPopup.DOWN, indexToActivate);
+            this._workspaceSwitcherPopup.display(direction, toActivate.index());
     },
-
-    actionMoveWorkspaceUp: function() {
-        let activeWorkspaceIndex = global.screen.get_active_workspace_index();
-        let indexToActivate = activeWorkspaceIndex;
-        if (activeWorkspaceIndex > 0)
-            indexToActivate--;
-
-        if (indexToActivate != activeWorkspaceIndex)
-            global.screen.get_workspace_by_index(indexToActivate).activate(global.get_current_time());
-
-        if (!Main.overview.visible)
-            this._workspaceSwitcherPopup.display(WorkspaceSwitcherPopup.UP, indexToActivate);
-    },
-
-    actionMoveWorkspaceDown: function() {
-        let activeWorkspaceIndex = global.screen.get_active_workspace_index();
-        let indexToActivate = activeWorkspaceIndex;
-        if (activeWorkspaceIndex < global.screen.n_workspaces - 1)
-            indexToActivate++;
-
-        if (indexToActivate != activeWorkspaceIndex)
-            global.screen.get_workspace_by_index(indexToActivate).activate(global.get_current_time());
-
-        if (!Main.overview.visible)
-            this._workspaceSwitcherPopup.display(WorkspaceSwitcherPopup.DOWN, indexToActivate);
-    }
 });
index 51d2c285993db7ebcc475b76f148bd8e23bb142b..1202d5f220f1e312e6ef083b5a188784ec21de23 100644 (file)
@@ -3,18 +3,16 @@
 const Clutter = imports.gi.Clutter;
 const Lang = imports.lang;
 const Mainloop = imports.mainloop;
+const Meta  = imports.gi.Meta;
 const Shell = imports.gi.Shell;
 const St = imports.gi.St;
-const Main = imports.ui.main;
 
+const Main = imports.ui.main;
 const Tweener = imports.ui.tweener;
 
 const ANIMATION_TIME = 0.1;
 const DISPLAY_TIMEOUT = 600;
 
-const UP = -1;
-const DOWN = 1;
-
 const WorkspaceSwitcherPopup = new Lang.Class({
     Name: 'WorkspaceSwitcherPopup',
 
@@ -110,9 +108,9 @@ const WorkspaceSwitcherPopup = new Lang.Class({
         for (let i = 0; i < global.screen.n_workspaces; i++) {
             let indicator = null;
 
-           if (i == activeWorkspaceIndex && direction == UP)
+           if (i == activeWorkspaceIndex && direction == Meta.MotionDirection.UP)
                indicator = new St.Bin({ style_class: 'ws-switcher-active-up' });
-           else if(i == activeWorkspaceIndex && direction == DOWN)
+           else if(i == activeWorkspaceIndex && direction == Meta.MotionDirection.DOWN)
                indicator = new St.Bin({ style_class: 'ws-switcher-active-down' });
            else
                indicator = new St.Bin({ style_class: 'ws-switcher-box' });
index df3143fefb4f0d51e2c2ad189608a00a7849ac0a..3a5c2ab37e7822a865b95be4616941fe5b29c576 100644 (file)
@@ -1048,10 +1048,10 @@ const WorkspacesDisplay = new Lang.Class({
     _onScrollEvent: function (actor, event) {
         switch ( event.get_scroll_direction() ) {
         case Clutter.ScrollDirection.UP:
-            Main.wm.actionMoveWorkspaceUp();
+            Main.wm.actionMoveWorkspace(Meta.MotionDirection.UP);
             break;
         case Clutter.ScrollDirection.DOWN:
-            Main.wm.actionMoveWorkspaceDown();
+            Main.wm.actionMoveWorkspace(Meta.MotionDirection.DOWN);
             break;
         }
     }